from datetime import datetime, timezone

from sqlmodel import SQLModel, Field, Relationship

from models.product import Product


class Image(SQLModel, table=True):
    id: int = Field(default=None, primary_key=True, index=True)
    image_url: str = Field(default=None)
    product_id: int | None = Field(default=None, foreign_key="product.id")
    product: Product | None = Relationship(back_populates="image")
    created_at: datetime | None = Field(default=datetime.now(timezone.utc))
